package com.cheer.ba.view.activity;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.cheer.ba.R;
import com.cheer.ba.model.ProvinceModel;
import com.cheer.ba.presenter.impl.OilMealPresenter;
import com.cheer.ba.view.base.BaseCommAty;
import com.cheer.pickerview.Util;

import java.util.ArrayList;
import java.util.Arrays;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 刷选送油条件-柴油
 */
public class SelectConditionAty extends BaseCommAty {

    //地区
    @BindView(R.id.id_oil_area_txt)
    TextView mTxtOilArea;
    private String mOilArea;
    private ArrayList<String> mProvinces = new ArrayList<String>();
    //油品种类
    @BindView(R.id.id_oil_type_txt)
    TextView mTxtOilType;
    private String mOilType;
    //油源
    @BindView(R.id.id_id_oil_original_txt)
    TextView mTxtOilOriginal;
    private String mOilOriginal;
    private ArrayList<String> mOilOriginals = new ArrayList<String>();
    private String[] originals = new String[]{"中国石油", "中国石化", "中国海油"};
    //全部
    @BindView(R.id.id_oil_rule_all_txt)
    TextView mTxtOilRuleAll;
    //国5
    @BindView(R.id.id_oil_rule_5_txt)
    TextView mTxtOilRule5;
    //普柴
    @BindView(R.id.id_oil_rule_nor_txt)
    TextView mTxtOilRuleNor;
    private String mOilRule;

    @Override
    public View loadView(LayoutInflater inflater, View childView) {
        return super.loadView(inflater, inflater.inflate(R.layout.aty_select_condition, null, false));
    }

    @Override
    public void initPresenter() {
        presenter = new OilMealPresenter();
    }

    @Override
    public void initView() {
        setTitleText(getString(R.string.select_condition));

        mOilArea = "湖北";
        mTxtOilArea.setText(mOilArea);
        mOilType = "柴油";
        mTxtOilType.setText(mOilType);
        mOilOriginal = "中囯石油";
        mTxtOilOriginal.setText(mOilOriginal);
        mTxtOilRuleAll.setSelected(true);

        //获得省级数据
        final ArrayList<ProvinceModel> provinces = (ArrayList<ProvinceModel>) ((OilMealPresenter) presenter).getData(4,false);
        if (null != provinces && !provinces.isEmpty()) {
            mProvinces.clear();
            for (ProvinceModel p : provinces) {
                mProvinces.add(p.mProvinceName);
            }
        }
        mOilOriginals.clear();
        mOilOriginals.addAll(Arrays.asList(originals));
    }

    @OnClick({R.id.id_choose_provs_rela, R.id.id_choose_oil_oirginal_rela, R.id.id_choose_sure_btn, R.id.id_oil_rule_all_rela, R.id.id_oil_rule_5_rela, R.id.id_oil_rule_nor_rela})
    public void onClick(View mView) {
        switch (mView.getId()) {
            //刷选区域
            case R.id.id_choose_provs_rela:
                Util.alertBottomWheelOption(aty, mProvinces, new Util.OnWheelViewClick() {
                    @Override
                    public void onClick(View view, int postion) {
                        mOilArea = mProvinces.get(postion);
                        mTxtOilArea.setText(mOilArea);
                    }
                }, 16);
                break;
            //油源
            case R.id.id_choose_oil_oirginal_rela:
                Util.alertBottomWheelOption(aty, mOilOriginals, new Util.OnWheelViewClick() {
                    @Override
                    public void onClick(View view, int postion) {
                        mOilOriginal = mOilOriginals.get(postion);
                        mTxtOilOriginal.setText(mOilOriginal);
                    }
                }, 0);
                break;
            //确定
            case R.id.id_choose_sure_btn:
                FindOilAty.startFindOilAty(aty, mOilArea, mOilType, mOilOriginal, mOilRule);
                break;
            //全部
            case R.id.id_oil_rule_all_rela:
                mTxtOilRuleAll.setSelected(true);
                mTxtOilRule5.setSelected(false);
                mTxtOilRuleNor.setSelected(false);
                break;
            //国5
            case R.id.id_oil_rule_5_rela:
                mTxtOilRuleAll.setSelected(false);
                mTxtOilRule5.setSelected(true);
                mTxtOilRuleNor.setSelected(false);
                break;
            //普柴
            case R.id.id_oil_rule_nor_rela:
                mTxtOilRuleAll.setSelected(false);
                mTxtOilRule5.setSelected(false);
                mTxtOilRuleNor.setSelected(true);
                break;
        }
    }
}
